package com.example.uitmanagement;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ArrayAdapterRegistry extends BaseAdapter {
	// XML node keys
    private Activity activity;
    private ArrayList<HashMap<String, String>> data;
    private static LayoutInflater inflater=null;   
    
    public ArrayAdapterRegistry(Activity a, ArrayList<HashMap<String, String>> d) {
        activity = a;
        data=d;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    public int getCount() {
        return data.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }
    
    public View getView(int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        if(convertView==null)
            vi = inflater.inflate(R.layout.registry_row, null);

        TextView subjectName = (TextView)vi.findViewById(R.id.subjectName); 
        TextView courseSize = (TextView)vi.findViewById(R.id.courseSize); 
        TextView lecturerName = (TextView)vi.findViewById(R.id.lecturerName); 
        TextView facultyID = (TextView)vi.findViewById(R.id.facultyID); 
        TextView schedule = (TextView)vi.findViewById(R.id.schedule); 
        TextView subjectTheory = (TextView)vi.findViewById(R.id.subjectTheory); 
        
        HashMap<String, String> array = new HashMap<String, String>();
        array = data.get(position);
        String a= "BAo cao :"+ position;
        Log.e(ArrayAdapterRegistry.class.toString(), a);
        // Setting all values in listview
        subjectName.setText(array.get(JsonParser.KEY_subjectName));
        courseSize.setText(array.get(JsonParser.KEY_courseSize));
        lecturerName.setText(array.get(JsonParser.KEY_lecturerName));
        facultyID.setText(array.get(JsonParser.KEY_facultyID));
        schedule.setText(array.get(JsonParser.KEY_schedule));
        subjectTheory.setText(array.get(JsonParser.KEY_subjectTheory));
        
        return vi;
    }
}